package com.torfox.modules.livelog;

import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalToIgnoringCase;

import java.util.LinkedList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.hamcrest.Matcher;

import ch.lambdaj.function.matcher.HasNestedPropertyWithValue;

import com.torfox.entities.LogRecord;

public class MatcherUtils
{

	static final String PARAMETER_LEVEL = "level";

	public static Matcher<LogRecord> fromRequest(final HttpServletRequest request)
    {
		final List<Matcher<? extends LogRecord>> matchers = new LinkedList<Matcher<? extends LogRecord>>();
		final String level = request.getParameter(PARAMETER_LEVEL);
		if( !StringUtils.isBlank(level))
		{
			matchers.add(new HasNestedPropertyWithValue<LogRecord>("level", equalToIgnoringCase(level)));
		}
	    return allOf(matchers);
    }

}
